<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\IntegralOrder;
use App\Http\Controllers\Common\CommonController;
use DB;


class IntegralOrderController extends Controller
{

	public function order()
    {
        $state = [0=>'新订单', 1=>'已发货', 2=>'已收货', 3=>'无效订单'];
    	
    	$order = DB::table('integral_order')
    				->join('users', 'integral_order.user_id', '=', 'users.id')
    				->join('integral_goods', 'integral_order.integral_goods_id', '=', 'integral_goods.id')
    				->select('integral_order.id', 'integral_order.order_number', 'integral_order.generation_time', 'integral_order.number', 'integral_order.consignee', 'integral_order.phone', 'integral_order.address', 'integral_order.integral_price', 'integral_order.order_status', 'users.name', 'integral_goods.ig_name')
    				->orderBy('integral_order.id', 'desc')
    				->paginate(6);

    	//dd($order);
    	return view('Admin/Integral/order', ['order' => $order, 'state' => $state]);
    	
    	
    }

    

    public function orderState($id)
    { 
		

		$status = IntegralOrder::select('id','order_status')->where('id', $id)->get();

		$sta = $status->toArray();

		$state = $sta[0]['order_status'];

		//dd($state);

		return view('Admin/Integral/orderEdit', ['status' => $status, 'state' => $state]);
    }

    public function orderUpdate(Request $request)
    { 
    	$common = new CommonController;
    	//return $request;
    	$id = $request->id;

    	$res = IntegralOrder::where('id', $id)->update([

    			'order_status' => $request->status,

    		]);

    	if ($res>0) { 

    		return $common->json(2032, '修改成功');
    	
    	} else { 

    		return $common->json(4023, '修改失败');

    	}

    }
}
